package com.eric;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yu huan
 * @date 2020-09-11
 */
public class CountOffGame {
  private static Map<Integer, String> baseRules = new HashMap<>();

  static {
    baseRules.put(0, "Fizz");
    baseRules.put(1, "Buzz");
    baseRules.put(2, "Whizz");
  }

  public static void countOff(int[] specialNums) {
    for (int i = 1; i <= 100; i++) {
      //优先满足规则三
      String result = thirdRule(i, specialNums[0]);
      if (result != null) {
        System.out.println(result);
        continue;
      }
      System.out.println(firstAndSecondRule(i, specialNums));
    }
  }

  private static String firstAndSecondRule(int number, int[] specialNums) {
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < specialNums.length; i++) {
      if (number % specialNums[i] == 0) {
        stringBuilder.append(baseRules.get(i));
      }
    }
    String result = stringBuilder.toString();
    if (result == null || result.equals("")) {
      return String.valueOf(number);
    }
    return result;
  }

  private static String thirdRule(int number, int firstSpecialNum) {
    String num = String.valueOf(number);
    String firstStr = String.valueOf(firstSpecialNum);
    String result = num.contains(firstStr) ? baseRules.get(0) : null;
    return result;
  }
}
